package main

import (
	"net/http"

	"github.com/julienschmidt/httprouter"
	"github.com/justinas/alice"
)

func (app *application) routes() http.Handler {

	router := httprouter.New()

	// not found 
	router.NotFound = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		app.notFound(w)
	})

	// file server
    fileServer := http.FileServer(http.Dir("./ui/static/"))
    router.Handler(http.MethodGet, "/static/*filepath", http.StripPrefix("/static", fileServer))

	
	//routes
	router.HandlerFunc(http.MethodGet,"/",app.home)
	router.HandlerFunc(http.MethodGet,"/snippet/view/:id",app.snippetView)
	router.HandlerFunc(http.MethodGet,"/snippet/create",app.snippetCreate)
	router.HandlerFunc(http.MethodPost,"/snippet/create",app.snippetCreatePost)
	
	// middleware chain
	standar := alice.New(app.recoverPanic,app.logRequest,secureHeaders)
	return standar.Then(router)
}
